package com.edu.ctgu;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Bill {

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            String startTimeStr = br.readLine();
            String endTimeStr = br.readLine();

            // 解析时间
            SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
            Date startDate = format.parse(startTimeStr);
            Date endDate = format.parse(endTimeStr);

            // 计算通话时长（分钟），考虑夏令时和冬令时转换
            long phoneTimeMinutes = calculateCallDuration(startDate, endDate);

            // 计算账单
            double bill = calculateBill(phoneTimeMinutes);

            // 输出结果
            System.out.println("通话时长：" + phoneTimeMinutes + " 分钟");
            System.out.println("通话账单：" + bill + " 美元");

        } catch (IOException | ParseException e) {
            e.printStackTrace();
        }
    }

    /**
     * 计算通话时长，考虑夏令时和冬令时转换
     */
    public static long calculateCallDuration(Date startDate, Date endDate) {
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(startDate);
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(endDate);

        // 计算通话时长（毫秒）
        long phoneTimeMillis = cal2.getTimeInMillis() - cal1.getTimeInMillis();

        // 检查是否涉及夏令时和冬令时转换
        if (isDaylightSavingsTransition(cal1, cal2)) {
            if (isFallBackTransition(cal1, cal2)) { // 冬令时转换（时钟回拨）
                phoneTimeMillis += 3600000; // 增加 1 小时
            } else if (isSpringForwardTransition(cal1, cal2)) { // 夏令时转换（时钟拨快）
                phoneTimeMillis -= 3600000; // 减少 1 小时
            }
        }

        // 将通话时长转换为分钟（不足一分钟按一分钟计算）
        return (phoneTimeMillis + 59999) / 60000; // 向上取整
    }

    /**
     * 判断是否涉及夏令时和冬令时转换
     */
    public static boolean isDaylightSavingsTransition(Calendar cal1, Calendar cal2) {
        return (isLastSundayOfMarch(cal1) && isLastSundayOfMarch(cal2)) ||
                (isFirstSundayOfNovember(cal1) && isFirstSundayOfNovember(cal2));
    }

    /**
     * 判断是否是冬令时转换（时钟回拨）
     */
    public static boolean isFallBackTransition(Calendar cal1, Calendar cal2) {
        return isFirstSundayOfNovember(cal1) && isFirstSundayOfNovember(cal2) &&
                cal1.get(Calendar.HOUR_OF_DAY) < 2 && cal2.get(Calendar.HOUR_OF_DAY) >= 2;
    }

    /**
     * 判断是否是夏令时转换（时钟拨快）
     */
    public static boolean isSpringForwardTransition(Calendar cal1, Calendar cal2) {
        return isLastSundayOfMarch(cal1) && isLastSundayOfMarch(cal2) &&
                cal1.get(Calendar.HOUR_OF_DAY) < 3 && cal2.get(Calendar.HOUR_OF_DAY) >= 3;
    }

    /**
     * 判断是否是 3 月的第二个周日
     */
    public static boolean isLastSundayOfMarch(Calendar cal) {
        return cal.get(Calendar.MONTH) == Calendar.MARCH &&
                cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY &&
                cal.get(Calendar.DATE) > 7&&cal.get(Calendar.DATE) < 14;
    }

    /**
     * 判断是否是 11 月的第一个周日
     */
    public static boolean isFirstSundayOfNovember(Calendar cal) {
        return cal.get(Calendar.MONTH) == Calendar.NOVEMBER &&
                cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY &&
                cal.get(Calendar.DATE) <= 7;
    }

    /**
     * 根据通话时长计算账单
     */
    public static double calculateBill(long minutes) {
        if (minutes <= 0 || minutes > 1800) { // 超过30小时（1800分钟）为无效输入
            throw new IllegalArgumentException("通话时间输入错误，请重新输入。");
        }

        if (minutes <= 20) {
            return minutes * 0.05;
        } else {
            return 1 + (minutes - 20) * 0.10;
        }
    }
}
